#line 1 "..\\SRC\\StdPeriphDriver\\CH57x_flash.c"






 

 
 
#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_common.h"



























 



   










#line 1 "d:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"
 
 
 
 




 








 












#line 38 "d:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"


  



    typedef unsigned int size_t;    
#line 54 "d:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"




extern __declspec(__nothrow) void *memcpy(void * __restrict  ,
                    const void * __restrict  , size_t  ) __attribute__((__nonnull__(1,2)));
   




 
extern __declspec(__nothrow) void *memmove(void *  ,
                    const void *  , size_t  ) __attribute__((__nonnull__(1,2)));
   







 
extern __declspec(__nothrow) char *strcpy(char * __restrict  , const char * __restrict  ) __attribute__((__nonnull__(1,2)));
   




 
extern __declspec(__nothrow) char *strncpy(char * __restrict  , const char * __restrict  , size_t  ) __attribute__((__nonnull__(1,2)));
   





 

extern __declspec(__nothrow) char *strcat(char * __restrict  , const char * __restrict  ) __attribute__((__nonnull__(1,2)));
   




 
extern __declspec(__nothrow) char *strncat(char * __restrict  , const char * __restrict  , size_t  ) __attribute__((__nonnull__(1,2)));
   






 






 

extern __declspec(__nothrow) int memcmp(const void *  , const void *  , size_t  ) __attribute__((__nonnull__(1,2)));
   





 
extern __declspec(__nothrow) int strcmp(const char *  , const char *  ) __attribute__((__nonnull__(1,2)));
   




 
extern __declspec(__nothrow) int strncmp(const char *  , const char *  , size_t  ) __attribute__((__nonnull__(1,2)));
   






 
extern __declspec(__nothrow) int strcasecmp(const char *  , const char *  ) __attribute__((__nonnull__(1,2)));
   





 
extern __declspec(__nothrow) int strncasecmp(const char *  , const char *  , size_t  ) __attribute__((__nonnull__(1,2)));
   






 
extern __declspec(__nothrow) int strcoll(const char *  , const char *  ) __attribute__((__nonnull__(1,2)));
   







 

extern __declspec(__nothrow) size_t strxfrm(char * __restrict  , const char * __restrict  , size_t  ) __attribute__((__nonnull__(2)));
   













 


#line 193 "d:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"
extern __declspec(__nothrow) void *memchr(const void *  , int  , size_t  ) __attribute__((__nonnull__(1)));

   





 

#line 209 "d:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"
extern __declspec(__nothrow) char *strchr(const char *  , int  ) __attribute__((__nonnull__(1)));

   




 

extern __declspec(__nothrow) size_t strcspn(const char *  , const char *  ) __attribute__((__nonnull__(1,2)));
   




 

#line 232 "d:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"
extern __declspec(__nothrow) char *strpbrk(const char *  , const char *  ) __attribute__((__nonnull__(1,2)));

   




 

#line 247 "d:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"
extern __declspec(__nothrow) char *strrchr(const char *  , int  ) __attribute__((__nonnull__(1)));

   





 

extern __declspec(__nothrow) size_t strspn(const char *  , const char *  ) __attribute__((__nonnull__(1,2)));
   



 

#line 270 "d:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"
extern __declspec(__nothrow) char *strstr(const char *  , const char *  ) __attribute__((__nonnull__(1,2)));

   





 

extern __declspec(__nothrow) char *strtok(char * __restrict  , const char * __restrict  ) __attribute__((__nonnull__(2)));
extern __declspec(__nothrow) char *_strtok_r(char *  , const char *  , char **  ) __attribute__((__nonnull__(2,3)));

extern __declspec(__nothrow) char *strtok_r(char *  , const char *  , char **  ) __attribute__((__nonnull__(2,3)));

   

































 

extern __declspec(__nothrow) void *memset(void *  , int  , size_t  ) __attribute__((__nonnull__(1)));
   



 
extern __declspec(__nothrow) char *strerror(int  );
   





 
extern __declspec(__nothrow) size_t strlen(const char *  ) __attribute__((__nonnull__(1)));
   



 

extern __declspec(__nothrow) size_t strlcpy(char *  , const char *  , size_t  ) __attribute__((__nonnull__(1,2)));
   
















 

extern __declspec(__nothrow) size_t strlcat(char *  , const char *  , size_t  ) __attribute__((__nonnull__(1,2)));
   






















 

extern __declspec(__nothrow) void _membitcpybl(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitcpybb(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitcpyhl(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitcpyhb(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitcpywl(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitcpywb(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitmovebl(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitmovebb(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitmovehl(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitmovehb(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitmovewl(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
extern __declspec(__nothrow) void _membitmovewb(void *  , const void *  , int  , int  , size_t  ) __attribute__((__nonnull__(1,2)));
    














































 







#line 502 "d:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\string.h"



 

#line 44 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_common.h"
#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_clk.h"










#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"
 
 
 
 
 










 
 

#line 26 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

#line 34 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"
typedef unsigned char           BOOL;


typedef unsigned char           BOOLEAN;


typedef char                    CHAR;


typedef char                    INT8;


typedef short                   INT16;


typedef long                    INT32;


typedef unsigned char           UINT8;


typedef unsigned short          UINT16;


typedef unsigned long           UINT32;


typedef unsigned char volatile  UINT8V;


typedef unsigned short volatile UINT16V;


typedef unsigned long volatile  UINT32V;



typedef void                    *PVOID;


typedef char                    *PCHAR;


typedef const char              *PCCHAR;


typedef char                    *PINT8;


typedef short                   *PINT16;


typedef long                    *PINT32;


typedef unsigned char           *PUINT8;


typedef unsigned short          *PUINT16;


typedef unsigned long           *PUINT32;


typedef volatile unsigned char  *PUINT8V;


typedef volatile unsigned short *PUINT16V;


typedef volatile unsigned long  *PUINT32V;


 
 

#line 116 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"







 


 


 


 

















 












































 

 

 
#line 211 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 220 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"










#line 242 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 254 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"







 
#line 284 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"












 
#line 325 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 339 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 355 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 












 
#line 381 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 401 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 410 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 






 
#line 425 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 453 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 471 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 482 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 502 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 528 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 556 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 693 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 708 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 730 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 752 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 767 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 805 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 827 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 847 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 867 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 887 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 957 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 966 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 990 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1007 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1059 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1076 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1114 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1128 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1140 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"





#line 1156 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1166 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"






 
#line 1181 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1189 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 


 
#line 1235 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"




typedef enum IRQn
{
 
  NonMaskableInt_IRQn          = -14,       
  HardFault_IRQn               = -13,       
  SVCall_IRQn                  =  -5,       
  PendSV_IRQn                  =  -2,       
  SysTick_IRQn                 =  -1,       
 
  TMR0_IRQn                    =   0,       
  GPIO_IRQn                    =   1,       
  SLAVE_IRQn                   =   2,       
  SPI0_IRQn                    =   3,       
  BLEB_IRQn                    =   4,       
  BLEL_IRQn                    =   5,       
  USB_IRQn                     =   6,       
  ETH_IRQn                     =   7,       
  TMR1_IRQn                    =   8,       
  TMR2_IRQn                    =   9,       
  UART0_IRQn                   =  10,       
  UART1_IRQn                   =  11,       
  RTC_IRQn                     =  12,       
  ADC_IRQn                     =  13,       
  SPI1_IRQn                    =  14,       
  LED_IRQn                     =  15,       
  TMR3_IRQn                    =  16,       
  UART2_IRQn                   =  17,       
  UART3_IRQn                   =  18,       
  WDOG_BAT_IRQn                =  19,       
} IRQn_Type;

















 
 
 

 


 
#line 1326 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

#line 1333 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

#line 1344 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

#line 1368 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"





























 
 
 

 


 
#line 1413 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"













#line 1433 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

#line 1441 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

#line 1451 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"





#line 1466 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

#line 1477 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

#line 1488 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"








#line 1502 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

















#line 1526 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"















#line 1563 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"





#line 1575 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"





































#line 1621 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"





















 

 
#line 1658 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1673 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1683 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1693 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1711 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1724 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1742 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1760 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1775 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

 
#line 1786 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"

#line 1804 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"






__packed typedef struct _USB_SETUP_REQ {
    UINT8 bRequestType;
    UINT8 bRequest;
    UINT16 wValue;
    UINT16 wIndex;
    UINT16 wLength;
} USB_SETUP_REQ, *PUSB_SETUP_REQ;


__packed typedef struct _USB_DEVICE_DESCR {
    UINT8 bLength;
    UINT8 bDescriptorType;
    UINT16 bcdUSB;
    UINT8 bDeviceClass;
    UINT8 bDeviceSubClass;
    UINT8 bDeviceProtocol;
    UINT8 bMaxPacketSize0;
    UINT16 idVendor;
    UINT16 idProduct;
    UINT16 bcdDevice;
    UINT8 iManufacturer;
    UINT8 iProduct;
    UINT8 iSerialNumber;
    UINT8 bNumConfigurations;
} USB_DEV_DESCR, *PUSB_DEV_DESCR;


__packed typedef struct _USB_CONFIG_DESCR {
    UINT8 bLength;
    UINT8 bDescriptorType;
    UINT16 wTotalLength;
    UINT8 bNumInterfaces;
    UINT8 bConfigurationValue;
    UINT8 iConfiguration;
    UINT8 bmAttributes;
    UINT8 MaxPower;
} USB_CFG_DESCR, *PUSB_CFG_DESCR;


__packed typedef struct _USB_INTERF_DESCR {
    UINT8 bLength;
    UINT8 bDescriptorType;
    UINT8 bInterfaceNumber;
    UINT8 bAlternateSetting;
    UINT8 bNumEndpoints;
    UINT8 bInterfaceClass;
    UINT8 bInterfaceSubClass;
    UINT8 bInterfaceProtocol;
    UINT8 iInterface;
} USB_ITF_DESCR, *PUSB_ITF_DESCR;


__packed typedef struct _USB_ENDPOINT_DESCR {
    UINT8 bLength;
    UINT8 bDescriptorType;
    UINT8 bEndpointAddress;
    UINT8 bmAttributes;
    UINT16 wMaxPacketSize;
    UINT8 bInterval;
} USB_ENDP_DESCR, *PUSB_ENDP_DESCR;


__packed typedef struct _USB_CONFIG_DESCR_LONG {
    USB_CFG_DESCR   cfg_descr;
    USB_ITF_DESCR   itf_descr;
    USB_ENDP_DESCR  endp_descr[1];
} USB_CFG_DESCR_LONG, *PUSB_CFG_DESCR_LONG;

typedef USB_CFG_DESCR_LONG *PXUSB_CFG_DESCR_LONG;

__packed typedef struct _USB_HUB_DESCR {
    UINT8 bDescLength;
    UINT8 bDescriptorType;
    UINT8 bNbrPorts;
    UINT8 wHubCharacteristicsL;
    UINT8 wHubCharacteristicsH;
    UINT8 bPwrOn2PwrGood;
    UINT8 bHubContrCurrent;
    UINT8 DeviceRemovable;
    UINT8 PortPwrCtrlMask;
} USB_HUB_DESCR, *PUSB_HUB_DESCR;

typedef USB_HUB_DESCR  *PXUSB_HUB_DESCR;

__packed typedef struct _USB_HID_DESCR {
    UINT8 bLength;
    UINT8 bDescriptorType;
    UINT16 bcdHID;
    UINT8 bCountryCode;
    UINT8 bNumDescriptors;
    UINT8 bDescriptorTypeX;
    UINT8 wDescriptorLengthL;
    UINT8 wDescriptorLengthH;
} USB_HID_DESCR, *PUSB_HID_DESCR;

typedef USB_HID_DESCR *PXUSB_HID_DESCR;


__packed typedef struct _UDISK_BOC_CBW {  
    UINT32 mCBW_Sig;
    UINT32 mCBW_Tag;
    UINT32 mCBW_DataLen;                 
    UINT8 mCBW_Flag;                     
    UINT8 mCBW_LUN;
    UINT8 mCBW_CB_Len;                   
    UINT8 mCBW_CB_Buf[16];               
} UDISK_BOC_CBW, *PUDISK_BOC_CBW;

typedef UDISK_BOC_CBW  *PXUDISK_BOC_CBW;

__packed typedef struct _UDISK_BOC_CSW {  
    UINT32 mCSW_Sig;
    UINT32 mCSW_Tag;
    UINT32 mCSW_Residue;                    
    UINT8 mCSW_Status;                   
} UDISK_BOC_CSW, *PUDISK_BOC_CSW;

typedef UDISK_BOC_CSW  *PXUDISK_BOC_CSW;






#line 12 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_clk.h"
#line 1 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
 







 

























 
























 




 


 

 













#line 110 "..\\SRC\\CMSIS\\Include\\core_cm0.h"



 







#line 146 "..\\SRC\\CMSIS\\Include\\core_cm0.h"

#line 1 "d:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdint.h"
 
 





 









     
#line 27 "d:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdint.h"
     











#line 46 "d:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdint.h"





 

     

     
typedef   signed          char int8_t;
typedef   signed short     int int16_t;
typedef   signed           int int32_t;
typedef   signed       __int64 int64_t;

     
typedef unsigned          char uint8_t;
typedef unsigned short     int uint16_t;
typedef unsigned           int uint32_t;
typedef unsigned       __int64 uint64_t;

     

     
     
typedef   signed          char int_least8_t;
typedef   signed short     int int_least16_t;
typedef   signed           int int_least32_t;
typedef   signed       __int64 int_least64_t;

     
typedef unsigned          char uint_least8_t;
typedef unsigned short     int uint_least16_t;
typedef unsigned           int uint_least32_t;
typedef unsigned       __int64 uint_least64_t;

     

     
typedef   signed           int int_fast8_t;
typedef   signed           int int_fast16_t;
typedef   signed           int int_fast32_t;
typedef   signed       __int64 int_fast64_t;

     
typedef unsigned           int uint_fast8_t;
typedef unsigned           int uint_fast16_t;
typedef unsigned           int uint_fast32_t;
typedef unsigned       __int64 uint_fast64_t;

     




typedef   signed           int intptr_t;
typedef unsigned           int uintptr_t;


     
typedef   signed     long long intmax_t;
typedef unsigned     long long uintmax_t;




     

     





     





     





     

     





     





     





     

     





     





     





     

     






     






     






     

     


     


     


     

     
#line 216 "d:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdint.h"

     



     






     
    
 



#line 241 "d:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdint.h"

     







     










     











#line 305 "d:\\Keil_v5\\ARM\\ARMCC\\Bin\\..\\include\\stdint.h"






 
#line 148 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
#line 1 "..\\SRC\\CMSIS\\Include\\core_cmInstr.h"
 







 

























 






 



 


 









 







 







 






 








 







 







 









 









 

__attribute__((section(".rev16_text"))) static __inline __asm uint32_t __REV16(uint32_t value)
{
  rev16 r0, r0
  bx lr
}








 

__attribute__((section(".revsh_text"))) static __inline __asm int32_t __REVSH(int32_t value)
{
  revsh r0, r0
  bx lr
}










 










 



#line 368 "..\\SRC\\CMSIS\\Include\\core_cmInstr.h"


#line 877 "..\\SRC\\CMSIS\\Include\\core_cmInstr.h"

   

#line 149 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
#line 1 "..\\SRC\\CMSIS\\Include\\core_cmFunc.h"
 







 

























 






 



 


 





 
 






 
static __inline uint32_t __get_CONTROL(void)
{
  register uint32_t __regControl         __asm("control");
  return(__regControl);
}







 
static __inline void __set_CONTROL(uint32_t control)
{
  register uint32_t __regControl         __asm("control");
  __regControl = control;
}







 
static __inline uint32_t __get_IPSR(void)
{
  register uint32_t __regIPSR          __asm("ipsr");
  return(__regIPSR);
}







 
static __inline uint32_t __get_APSR(void)
{
  register uint32_t __regAPSR          __asm("apsr");
  return(__regAPSR);
}







 
static __inline uint32_t __get_xPSR(void)
{
  register uint32_t __regXPSR          __asm("xpsr");
  return(__regXPSR);
}







 
static __inline uint32_t __get_PSP(void)
{
  register uint32_t __regProcessStackPointer  __asm("psp");
  return(__regProcessStackPointer);
}







 
static __inline void __set_PSP(uint32_t topOfProcStack)
{
  register uint32_t __regProcessStackPointer  __asm("psp");
  __regProcessStackPointer = topOfProcStack;
}







 
static __inline uint32_t __get_MSP(void)
{
  register uint32_t __regMainStackPointer     __asm("msp");
  return(__regMainStackPointer);
}







 
static __inline void __set_MSP(uint32_t topOfMainStack)
{
  register uint32_t __regMainStackPointer     __asm("msp");
  __regMainStackPointer = topOfMainStack;
}







 
static __inline uint32_t __get_PRIMASK(void)
{
  register uint32_t __regPriMask         __asm("primask");
  return(__regPriMask);
}







 
static __inline void __set_PRIMASK(uint32_t priMask)
{
  register uint32_t __regPriMask         __asm("primask");
  __regPriMask = (priMask);
}


#line 271 "..\\SRC\\CMSIS\\Include\\core_cmFunc.h"


#line 307 "..\\SRC\\CMSIS\\Include\\core_cmFunc.h"


#line 634 "..\\SRC\\CMSIS\\Include\\core_cmFunc.h"

 

#line 150 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
















 
#line 183 "..\\SRC\\CMSIS\\Include\\core_cm0.h"

 






 
#line 199 "..\\SRC\\CMSIS\\Include\\core_cm0.h"

 










 


 





 


 
typedef union
{
  struct
  {

    uint32_t _reserved0:27;               





    uint32_t Q:1;                         
    uint32_t V:1;                         
    uint32_t C:1;                         
    uint32_t Z:1;                         
    uint32_t N:1;                         
  } b;                                    
  uint32_t w;                             
} APSR_Type;



 
typedef union
{
  struct
  {
    uint32_t ISR:9;                       
    uint32_t _reserved0:23;               
  } b;                                    
  uint32_t w;                             
} IPSR_Type;



 
typedef union
{
  struct
  {
    uint32_t ISR:9;                       

    uint32_t _reserved0:15;               





    uint32_t T:1;                         
    uint32_t IT:2;                        
    uint32_t Q:1;                         
    uint32_t V:1;                         
    uint32_t C:1;                         
    uint32_t Z:1;                         
    uint32_t N:1;                         
  } b;                                    
  uint32_t w;                             
} xPSR_Type;



 
typedef union
{
  struct
  {
    uint32_t nPRIV:1;                     
    uint32_t SPSEL:1;                     
    uint32_t FPCA:1;                      
    uint32_t _reserved0:29;               
  } b;                                    
  uint32_t w;                             
} CONTROL_Type;

 






 


 
typedef struct
{
  volatile uint32_t ISER[1];                  
       uint32_t RESERVED0[31];
  volatile uint32_t ICER[1];                  
       uint32_t RSERVED1[31];
  volatile uint32_t ISPR[1];                  
       uint32_t RESERVED2[31];
  volatile uint32_t ICPR[1];                  
       uint32_t RESERVED3[31];
       uint32_t RESERVED4[64];
  volatile uint32_t IP[8];                    
}  NVIC_Type;

 






 


 
typedef struct
{
  volatile const  uint32_t CPUID;                    
  volatile uint32_t ICSR;                     
       uint32_t RESERVED0;
  volatile uint32_t AIRCR;                    
  volatile uint32_t SCR;                      
  volatile uint32_t CCR;                      
       uint32_t RESERVED1;
  volatile uint32_t SHP[2];                   
  volatile uint32_t SHCSR;                    
} SCB_Type;

 















 



























 















 









 






 



 






 


 
typedef struct
{
  volatile uint32_t CTRL;                     
  volatile uint32_t LOAD;                     
  volatile uint32_t VAL;                      
  volatile const  uint32_t CALIB;                    
} SysTick_Type;

 












 



 



 









 








 
 






 

 










 









 

 



 




 

 
 










 
static __inline void NVIC_EnableIRQ(IRQn_Type IRQn)
{
  ((NVIC_Type *) ((0xE000E000UL) + 0x0100UL) )->ISER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}







 
static __inline void NVIC_DisableIRQ(IRQn_Type IRQn)
{
  ((NVIC_Type *) ((0xE000E000UL) + 0x0100UL) )->ICER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}











 
static __inline uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
{
  return((uint32_t) ((((NVIC_Type *) ((0xE000E000UL) + 0x0100UL) )->ISPR[0] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0));
}







 
static __inline void NVIC_SetPendingIRQ(IRQn_Type IRQn)
{
  ((NVIC_Type *) ((0xE000E000UL) + 0x0100UL) )->ISPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}







 
static __inline void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
{
  ((NVIC_Type *) ((0xE000E000UL) + 0x0100UL) )->ICPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F));  
}










 
static __inline void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
{
  if(IRQn < 0) {
    ((SCB_Type *) ((0xE000E000UL) + 0x0D00UL) )->SHP[( ((((uint32_t)(IRQn) & 0x0F)-8) >> 2) )] = (((SCB_Type *) ((0xE000E000UL) + 0x0D00UL) )->SHP[( ((((uint32_t)(IRQn) & 0x0F)-8) >> 2) )] & ~(0xFF << ( (((uint32_t)(IRQn) ) & 0x03) * 8 ))) |
        (((priority << (8 - 2)) & 0xFF) << ( (((uint32_t)(IRQn) ) & 0x03) * 8 )); }
  else {
    ((NVIC_Type *) ((0xE000E000UL) + 0x0100UL) )->IP[( ((uint32_t)(IRQn) >> 2) )] = (((NVIC_Type *) ((0xE000E000UL) + 0x0100UL) )->IP[( ((uint32_t)(IRQn) >> 2) )] & ~(0xFF << ( (((uint32_t)(IRQn) ) & 0x03) * 8 ))) |
        (((priority << (8 - 2)) & 0xFF) << ( (((uint32_t)(IRQn) ) & 0x03) * 8 )); }
}












 
static __inline uint32_t NVIC_GetPriority(IRQn_Type IRQn)
{

  if(IRQn < 0) {
    return((uint32_t)(((((SCB_Type *) ((0xE000E000UL) + 0x0D00UL) )->SHP[( ((((uint32_t)(IRQn) & 0x0F)-8) >> 2) )] >> ( (((uint32_t)(IRQn) ) & 0x03) * 8 ) ) & 0xFF) >> (8 - 2)));  }  
  else {
    return((uint32_t)(((((NVIC_Type *) ((0xE000E000UL) + 0x0100UL) )->IP[ ( ((uint32_t)(IRQn) >> 2) )] >> ( (((uint32_t)(IRQn) ) & 0x03) * 8 ) ) & 0xFF) >> (8 - 2)));  }  
}





 
static __inline void NVIC_SystemReset(void)
{
  __dsb(0xF);                                                     
 
  ((SCB_Type *) ((0xE000E000UL) + 0x0D00UL) )->AIRCR  = ((0x5FA << 16)      |
                 (1UL << 2));
  __dsb(0xF);                                                      
  while(1);                                                     
}

 



 




 

















 
static __inline uint32_t SysTick_Config(uint32_t ticks)
{
  if ((ticks - 1) > (0xFFFFFFUL << 0))  return (1);       

  ((SysTick_Type *) ((0xE000E000UL) + 0x0010UL) )->LOAD  = ticks - 1;                                   
  NVIC_SetPriority (SysTick_IRQn, (1<<2) - 1);   
  ((SysTick_Type *) ((0xE000E000UL) + 0x0010UL) )->VAL   = 0;                                           
  ((SysTick_Type *) ((0xE000E000UL) + 0x0010UL) )->CTRL  = (1UL << 2) |
                   (1UL << 1)   |
                   (1UL << 0);                     
  return (0);                                                   
}



 










#line 13 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_clk.h"

typedef enum
{
	CLK_SOURCE_LSI = 0,
	CLK_SOURCE_LSE,
	CLK_SOURCE_HSE_32MHz,
	CLK_SOURCE_HSE_16MHz,
	CLK_SOURCE_HSE_8MHz,
	CLK_SOURCE_HSI_32MHz,				
	CLK_SOURCE_HSI_16MHz,
	CLK_SOURCE_HSI_8MHz,
	CLK_SOURCE_PLL_40MHz,
	CLK_SOURCE_PLL_32MHz,
	CLK_SOURCE_PLL_24MHz,
	CLK_SOURCE_PLL_20MHz,
	CLK_SOURCE_PLL_16MHz,
	
}SYS_CLKTypeDef;


typedef enum
{
	Clk32M_HSI = 0,
	Clk32M_HSE,
	
}HClk32MTypeDef;

typedef enum
{
	Clk32K_LSI = 0,
	Clk32K_LSE,
	
}LClk32KTypeDef;

typedef enum
{
	HSE_RCur_75 = 0,
	HSE_RCur_100,
    HSE_RCur_125,
    HSE_RCur_150
	
}HSECurrentTypeDef;

typedef enum
{
	HSECap_10p = 0,
	HSECap_12p,  HSECap_14p,  HSECap_16p,  HSECap_18p,  
    HSECap_20p,  HSECap_22p,  HSECap_24p
	
}HSECapTypeDef;

typedef enum
{
	LSE_RCur_70 = 0,
	LSE_RCur_100,
    LSE_RCur_140,
    LSE_RCur_200
	
}LSECurrentTypeDef;

typedef enum
{
	LSECap_2p = 0,
	LSECap_13p,  LSECap_14p,  LSECap_15p,  LSECap_16p,  
    LSECap_17p,  LSECap_18p,  LSECap_19p,  LSECap_20p,
    LSECap_21p,  LSECap_22p,  LSECap_23p,  LSECap_24p,
    LSECap_25p,  LSECap_26p,  LSECap_27p
	
}LSECapTypeDef;








 
typedef enum
{
	Period_0_125_S = 0,			
	Period_0_25_S,				
	Period_0_5_S,				
	Period_1_S,					
	Period_2_S,					
	Period_4_S,					
	Period_8_S,					
	Period_16_S,				
}RTC_TMRCycTypeDef;	 
	 



 
typedef enum
{
	RTC_TRIG_EVENT = 0,			
	RTC_TMR_EVENT,				

}RTC_EVENTTypeDef;	 



 
typedef enum
{
	RTC_TRIG_MODE = 0,			
	RTC_TMR_MODE,				

}RTC_MODETypeDef;


void SystemInit(void);							 	 
void SetSysClock( SYS_CLKTypeDef sc);			 
UINT32 GetSysClock( void );						 	
void HClk32M_Select( HClk32MTypeDef hc);		 
void LClk32K_Select( LClk32KTypeDef hc);		 

void HSECFG_Current( HSECurrentTypeDef c );      
void HSECFG_Capacitance( HSECapTypeDef c );      
void LSECFG_Current( LSECurrentTypeDef c );      
void LSECFG_Capacitance( LSECapTypeDef c );      

UINT16 Calibration_LSI( void );				 

	 
void RTC_InitTime( UINT32 h, UINT16 m, UINT16 s );			 
void RTC_GetTime( PUINT32 ph, PUINT16 pm, PUINT16 ps );		 
	 
void RTC_SetCycle32k( UINT32 cyc );							 	 
UINT32 RTC_GetCycle32k( void );				                 

void RTC_TRIGFunCfg( UINT32 cyc );							 
void RTC_TMRFunCfg( RTC_TMRCycTypeDef t );					 
void RTC_ModeFunDisable( RTC_MODETypeDef m );                

UINT8 RTC_GetITFlag( RTC_EVENTTypeDef f );					 	 
void RTC_ClearITFlag( RTC_EVENTTypeDef f );					  

	 

	 






#line 45 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_common.h"
#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_uart.h"










#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"
 
 
 
 
 



#line 141 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1277 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1388 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1633 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 12 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_uart.h"
#line 1 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
 







 

























 






#line 156 "..\\SRC\\CMSIS\\Include\\core_cm0.h"



#line 710 "..\\SRC\\CMSIS\\Include\\core_cm0.h"

#line 13 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_uart.h"




      




     







      
typedef enum
{
	UART_1BYTE_TRIG = 0,        
	UART_2BYTE_TRIG,            
	UART_4BYTE_TRIG,            
	UART_7BYTE_TRIG,            
	
}UARTByteTRIGTypeDef;     
 
 
  
void UART0_DefInit( void );	 							 
void UART0_BaudRateCfg( UINT32 baudrate );	 			 
void UART0_ByteTrigCfg( UARTByteTRIGTypeDef b );         
void UART0_INTCfg( UINT8 s,  UINT8 i );		             
void UART0_Reset( void );								 









void UART0_SendString( PUINT8 buf, UINT16 l );			 

UINT16 UART0_RecvString( PUINT8 buf );					 

 
     
  	 
void UART1_DefInit( void );	 							 
void UART1_BaudRateCfg( UINT32 baudrate );	 			 
void UART1_ByteTrigCfg( UARTByteTRIGTypeDef b );         
void UART1_INTCfg( UINT8 s,  UINT8 i );		             
void UART1_Reset( void );								 









void UART1_SendString( PUINT8 buf, UINT16 l );			 

UINT16 UART1_RecvString( PUINT8 buf );					 



  
void UART2_DefInit( void );	 							 
void UART2_BaudRateCfg( UINT32 baudrate );	 			 
void UART2_ByteTrigCfg( UARTByteTRIGTypeDef b );         
void UART2_INTCfg( UINT8 s,  UINT8 i );		             
void UART2_Reset( void );								 









void UART2_SendString( PUINT8 buf, UINT16 l );			 

UINT16 UART2_RecvString( PUINT8 buf );					 




  
void UART3_DefInit( void );	 							 
void UART3_BaudRateCfg( UINT32 baudrate );	 			 
void UART3_ByteTrigCfg( UARTByteTRIGTypeDef b );         
void UART3_INTCfg( UINT8 s,  UINT8 i );		             
void UART3_Reset( void );								 









void UART3_SendString( PUINT8 buf, UINT16 l );			 

UINT16 UART3_RecvString( PUINT8 buf );					 

	 
	 






#line 46 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_common.h"
#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_gpio.h"










#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"
 
 
 
 
 



#line 141 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1277 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1388 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1633 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 12 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_gpio.h"
#line 1 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
 







 

























 






#line 156 "..\\SRC\\CMSIS\\Include\\core_cm0.h"



#line 710 "..\\SRC\\CMSIS\\Include\\core_cm0.h"

#line 13 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_gpio.h"



 
#line 42 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_gpio.h"
	 


 
typedef enum
{
    GPIO_ModeIN_Floating,			
    GPIO_ModeIN_PU,					
    GPIO_ModeIN_PD,					
    GPIO_ModeOut_PP_5mA,			
    GPIO_ModeOut_PP_20mA,			

}GPIOModeTypeDef;



 
typedef enum
{
    GPIO_ITMode_LowLevel,			
    GPIO_ITMode_HighLevel,			
    GPIO_ITMode_FallEdge,			
    GPIO_ITMode_RiseEdge,			

}GPIOITModeTpDef;



		
void GPIOA_ModeCfg( UINT32 pin, GPIOModeTypeDef mode );				 
void GPIOB_ModeCfg( UINT32 pin, GPIOModeTypeDef mode );				 
#line 83 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_gpio.h"

void GPIOA_ITModeCfg( UINT32 pin, GPIOITModeTpDef mode );			 
void GPIOB_ITModeCfg( UINT32 pin, GPIOITModeTpDef mode );			 
#line 92 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_gpio.h"

void GPIOPinRemap( UINT8 s, UINT16 perph );				 
void GPIOAGPPCfg( UINT8 s, UINT16 perph );				 
	 
	 






#line 47 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_common.h"
#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_lcd.h"










#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"
 
 
 
 
 



#line 141 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1277 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1388 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1633 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 12 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_lcd.h"
#line 1 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
 







 

























 






#line 156 "..\\SRC\\CMSIS\\Include\\core_cm0.h"



#line 710 "..\\SRC\\CMSIS\\Include\\core_cm0.h"

#line 13 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_lcd.h"



 
typedef enum
{
	LCD_PS_3V3 = 0,					
	LCD_PS_2V5,						
}LCDDrvPowerTypeDef; 
	 
	 


 
typedef enum
{
	LCD_1_2_Bias = 0,				
	LCD_1_3_Bias,					
}LCDBiasTypeDef;



 
typedef enum
{
	LCD_1_2_Duty = 0,				
	LCD_1_3_Duty,					
	LCD_1_4_Duty,					
}LCDDutyTypeDef;



 
typedef enum
{
	LCD_CLK_256 = 0,				
	LCD_CLK_512,					
	LCD_CLK_1000,					
	LCD_CLK_128						
}LCDSCANCLKTypeDef;
	 
	 
void LCD_DefInit( void );				 












	 




	 




	 






	 






#line 48 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_common.h"
#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_flash.h"










#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"
 
 
 
 
 



#line 141 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1277 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1388 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1633 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 12 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_flash.h"
#line 1 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
 







 

























 






#line 156 "..\\SRC\\CMSIS\\Include\\core_cm0.h"



#line 710 "..\\SRC\\CMSIS\\Include\\core_cm0.h"

#line 13 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_flash.h"
     




void GetUniqueID(PUINT8 buf);                                                
     

void GetMACAddress(PUINT8 buf);                                             


UINT8 FlashBlockErase(UINT32 addr);     
UINT8 FlashWriteDW(UINT32 addr, UINT32 dat);
UINT8 FlashWriteBuf(UINT32 addr, PUINT32 pdat, UINT16 len);	 

	 
	 






#line 49 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_common.h"
#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_pwr.h"










#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"
 
 
 
 
 



#line 141 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1277 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1388 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1633 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 12 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_pwr.h"
#line 1 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
 







 

























 






#line 156 "..\\SRC\\CMSIS\\Include\\core_cm0.h"



#line 710 "..\\SRC\\CMSIS\\Include\\core_cm0.h"

#line 13 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_pwr.h"



 
#line 36 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_pwr.h"



 
#line 46 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_pwr.h"


void PWR_DCDCCfg( UINT8 s );	                                
void PWR_UnitModCfg( UINT8 s, UINT8 unit );                    
void PWR_PeriphClkCfg( UINT8 s, UINT16 perph );                

void PowerMonitor( UINT8 s );                                  

void PWR_PeriphWakeUpCfg( UINT8 s, UINT16 perph );               
void LowPower_Idle( void );                                  	 
void LowPower_Halt_1( void );                                
void LowPower_Halt_2( void );                                
void LowPower_Sleep( UINT8 rm );                             
void LowPower_Shutdown( UINT8 rm );                          
void EnterCodeUpgrade( void );								 

	 
	 






#line 50 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_common.h"
#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_pwm.h"










#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"
 
 
 
 
 



#line 141 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1277 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1388 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1633 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 12 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_pwm.h"
#line 1 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
 







 

























 






#line 156 "..\\SRC\\CMSIS\\Include\\core_cm0.h"



#line 710 "..\\SRC\\CMSIS\\Include\\core_cm0.h"

#line 13 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_pwm.h"



 

#line 26 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_pwm.h"
	




 
typedef enum
{
	High_Level = 0,						
	Low_Level,							
}PWMX_PolarTypeDef;	 
	 



 
typedef enum
{
	PWMX_Cycle_256 = 0,					
	PWMX_Cycle_255,						
	PWMX_Cycle_128,						
	PWMX_Cycle_127,						
	PWMX_Cycle_64,						
	PWMX_Cycle_63,						
	PWMX_Cycle_32,						
	PWMX_Cycle_31,						
}PWMX_CycleTypeDef;	 
	 


void PWMX_CycleCfg( PWMX_CycleTypeDef cyc );							 

#line 66 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_pwm.h"


void PWMX_ACTOUT( UINT8 ch, UINT8 da, PWMX_PolarTypeDef pr, UINT8 s);	 
void PWMX_AlterOutCfg( UINT8 ch, UINT8 s);			 




	 






#line 51 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_common.h"
#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_adc.h"










#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"
 
 
 
 
 



#line 141 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1277 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1388 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1633 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 12 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_adc.h"
#line 1 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
 







 

























 






#line 156 "..\\SRC\\CMSIS\\Include\\core_cm0.h"



#line 710 "..\\SRC\\CMSIS\\Include\\core_cm0.h"

#line 13 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_adc.h"

     


     



 
typedef enum
{
	CH_EXTIN_0 = 0,			
	CH_EXTIN_1,				
	CH_EXTIN_2,				
	CH_EXTIN_3,				
	CH_EXTIN_4,				
	CH_EXTIN_5,				
	CH_EXTIN_6,				
	CH_EXTIN_7,				
	CH_EXTIN_8,				
	CH_EXTIN_9,				
	CH_EXTIN_10,			
	CH_EXTIN_11,			
	CH_EXTIN_12,			
	CH_EXTIN_13,			
	
	CH_INTE_VBAT,			
	CH_INTE_VTEMP,			

}ADC_SingleChannelTypeDef;



 
typedef enum
{
	CH_DIFF_0_2 = 0,			
	CH_DIFF_1_3,				

}ADC_DiffChannelTypeDef;



 
typedef enum
{
	SampleFreq_3_2 = 0,			
	SampleFreq_2_67,			
	SampleFreq_5_33,			
	SampleFreq_4,				
}ADC_SampClkTypeDef;




 
typedef enum
{
	ADC_PGA_1_4 = 0,			
	ADC_PGA_1_2,				
	ADC_PGA_0,					
	ADC_PGA_2,					
}ADC_SignalPGATypeDef;










void ADC_ExtSingleChSampInit( ADC_SampClkTypeDef sp, ADC_SignalPGATypeDef ga );						 
void ADC_ExtDiffChSampInit( ADC_SampClkTypeDef sp, ADC_SignalPGATypeDef ga );						 
void TouchKey_ChSampInit( void );                                                                    
void ADC_InterTSSampInit( void );																	 
void ADC_InterBATSampInit( void );																	 

UINT16 ADC_ExcutSingleConver( void );																 
signed short ADC_DataCalib_Rough( void ); 
void ADC_DataCalib_Fine( PUINT16 dat, ADC_SignalPGATypeDef ga );
UINT16 TouchKey_ExcutSingleConver( UINT8 d );														 
int ADC_GetCurrentTS( UINT16 ts_v );                                                               









	 






#line 52 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_common.h"
#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_sys.h"










#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"
 
 
 
 
 



#line 141 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1277 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1388 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1633 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 12 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_sys.h"
#line 1 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
 







 

























 






#line 156 "..\\SRC\\CMSIS\\Include\\core_cm0.h"



#line 710 "..\\SRC\\CMSIS\\Include\\core_cm0.h"

#line 13 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_sys.h"

	 
	 


 
typedef enum
{
	RST_STATUS_SW = 0,			
	RST_STATUS_RPOR,			
	RST_STATUS_WTR,				
	RST_STATUS_MR,				
	RST_STATUS_LRM0,			
	RST_STATUS_GPWSM,			
	RST_STATUS_LRM1,			
	RST_STATUS_LRM2,			

}SYS_ResetStaTypeDef;



 
typedef enum
{
	INFO_ROM_READ = 0,			
	INFO_RESET_EN = 2,			
	INFO_BOOT_EN,				
	INFO_DEBUG_EN,				
	INFO_LOADER,				
	STA_SAFEACC_ACT,			

}SYS_InfoStaTypeDef;
	 



UINT8 SYS_GetInfoSta( SYS_InfoStaTypeDef i );									 


void SYS_ResetExecute( void );													 


void SYS_DisableAllIrq( PUINT32 pirqv);									         
void SYS_RecoverIrq( UINT32 irq_status );									     
UINT32 SYS_GetSysTickCnt( void );												 


void  WWDG_ITCfg( UINT8 s );							 
void  WWDG_ResetCfg( UINT8 s );							 

void WWDG_ClearFlag(void);														 


void mDelayuS( UINT16 t );		 
void mDelaymS( UINT16 t );		 









#line 53 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_common.h"
#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_timer.h"










#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"
 
 
 
 
 



#line 141 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1277 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1388 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1633 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 12 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_timer.h"
#line 1 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
 







 

























 






#line 156 "..\\SRC\\CMSIS\\Include\\core_cm0.h"



#line 710 "..\\SRC\\CMSIS\\Include\\core_cm0.h"

#line 13 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_timer.h"






 






	 
	 


 
typedef enum
{
	PWM_Times_1 = 0,					
	PWM_Times_4,						
	PWM_Times_8,						
	PWM_Times_16,						
}PWM_RepeatTsTypeDef;	




 
typedef enum
{
	CAP_NULL = 0,						
	Edge_To_Edge,						
	FallEdge_To_FallEdge,				
	RiseEdge_To_RiseEdge,				
}CapModeTypeDef;



 
typedef enum
{
	Mode_Single = 0,				
	Mode_LOOP,						
}DMAModeTypeDef;


 

void TMR0_TimerInit( UINT32 t );									 	 
void TMR0_EXTSingleCounterInit( UINT32 c );							 




void TMR0_PWMInit( PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts );	 	 

	 


void TMR0_CapInit( CapModeTypeDef cap );							 












 

void TMR1_TimerInit( UINT32 t );									 	 
void TMR1_EXTSingleCounterInit( UINT32 c );							 




void TMR1_PWMInit( PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts );	 	 

	 


void TMR1_CapInit( CapModeTypeDef cap );							 



void TMR1_DMACfg( UINT8 s, UINT16 startAddr, UINT16 endAddr, DMAModeTypeDef m );     









 

void TMR2_TimerInit( UINT32 t );									 	 
void TMR2_EXTSingleCounterInit( UINT32 c );							 




void TMR2_PWMInit( PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts );	 	 

	 


void TMR2_CapInit( CapModeTypeDef cap );							 



void TMR2_DMACfg( UINT8 s, UINT16 startAddr, UINT16 endAddr, DMAModeTypeDef m );     









 

void TMR3_TimerInit( UINT32 t );									 	 
void TMR3_EXTSingleCounterInit( UINT32 c );							 




void TMR3_PWMInit( PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts );	 	 

	 


void TMR3_CapInit( CapModeTypeDef cap );							 












	 






#line 54 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_common.h"
#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_spi.h"










#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"
 
 
 
 
 



#line 141 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1277 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1388 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1633 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 12 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_spi.h"
#line 1 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
 







 

























 






#line 156 "..\\SRC\\CMSIS\\Include\\core_cm0.h"



#line 710 "..\\SRC\\CMSIS\\Include\\core_cm0.h"

#line 13 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_spi.h"



 

#line 24 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_spi.h"
	 
	 
	 


 
typedef enum
{
	Mode0_LowBitINFront = 0,					
	Mode0_HighBitINFront,						
	Mode3_LowBitINFront,						
	Mode3_HighBitINFront,						
}ModeBitOrderTypeDef;




 
typedef enum
{
	Mode_DataStream = 0,				
	Mose_FirstCmd,						
}Slave_ModeTypeDef;
	 
	 
 	 
void SPI0_MasterDefInit( void );                             
void SPI0_CLKCfg( UINT8 c );                                  	 
void SPI0_DataMode( ModeBitOrderTypeDef m );                 	 

void SPI0_MasterSendByte( UINT8 d );                         
UINT8 SPI0_MasterRecvByte( void );                           

void SPI0_MasterTrans( UINT8 *pbuf, UINT16 len );            	 
void SPI0_MasterRecv( UINT8 *pbuf, UINT16 len );             

void SPI0_MasterDMATrans( PUINT8 pbuf, UINT16 len);			 
void SPI0_MasterDMARecv( PUINT8 pbuf, UINT16 len);			 


void SPI0_SlaveInit( void );			                     

void SPI0_SlaveSendByte( UINT8 d );			                 
UINT8 SPI0_SlaveRecvByte( void );			                 

void SPI0_SlaveTrans( UINT8 *pbuf, UINT16 len );             
void SPI0_SlaveRecv( PUINT8 pbuf, UINT16 len );              

void SPI0_SlaveDMATrans( PUINT8 pbuf, UINT16 len);           
void SPI0_SlaveDMARecv( PUINT8 pbuf, UINT16 len);            









 
void SPI1_MasterDefInit( void );                             
void SPI1_CLKCfg( UINT8 c );                                  	 
void SPI1_DataMode( ModeBitOrderTypeDef m );                 	 

void SPI1_MasterSendByte( UINT8 d );                         
UINT8 SPI1_MasterRecvByte( void );                           

void SPI1_MasterTrans( UINT8 *pbuf, UINT16 len );            	 
void SPI1_MasterRecv( UINT8 *pbuf, UINT16 len );             









	 






#line 55 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_common.h"
#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_usbdev.h"










#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"
 
 
 
 
 



#line 141 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1277 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1388 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1633 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 12 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_usbdev.h"
#line 1 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
 







 

























 






#line 156 "..\\SRC\\CMSIS\\Include\\core_cm0.h"



#line 710 "..\\SRC\\CMSIS\\Include\\core_cm0.h"

#line 13 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_usbdev.h"

 
extern PUINT8  pEP0_RAM_Addr;		
extern PUINT8  pEP1_RAM_Addr;		
extern PUINT8  pEP2_RAM_Addr;		
extern PUINT8  pEP3_RAM_Addr;		

#line 30 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_usbdev.h"
	 

	 
void USB_DeviceInit( void );			 	 
void USB_DevTransProcess( void );		 	 
	 
void DevEP1_OUT_Deal( UINT8 l );		 
void DevEP2_OUT_Deal( UINT8 l );		 
void DevEP3_OUT_Deal( UINT8 l );		 
void DevEP4_OUT_Deal( UINT8 l );		 

void DevEP1_IN_Deal( UINT8 l );		 
void DevEP2_IN_Deal( UINT8 l );		 
void DevEP3_IN_Deal( UINT8 l );		 
void DevEP4_IN_Deal( UINT8 l );		 








	 






#line 56 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_common.h"
#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_usbhost.h"










#line 1 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"
 
 
 
 
 



#line 141 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1277 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1388 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 1633 "..\\SRC\\StdPeriphDriver\\inc\\CH579SFR.h"


#line 12 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_usbhost.h"
#line 1 "..\\SRC\\CMSIS\\Include\\core_cm0.h"
 







 

























 






#line 156 "..\\SRC\\CMSIS\\Include\\core_cm0.h"



#line 710 "..\\SRC\\CMSIS\\Include\\core_cm0.h"

#line 13 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_usbhost.h"

 

 

    
     
     

#line 31 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_usbhost.h"

 
#line 41 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_usbhost.h"







 




typedef struct
{
    UINT8   DeviceStatus;              
    UINT8   DeviceAddress;             
    UINT8   DeviceSpeed;               
    UINT8   DeviceType;                
    UINT16  DeviceVID;
    UINT16  DevicePID;
    UINT8   GpVar[4];                    
    UINT8   GpHUBPortNum;                
} _RootHubDev;


extern _RootHubDev  ThisUsbDev;
extern UINT8  UsbDevEndp0Size;              
extern UINT8  FoundNewDev;

extern PUINT8  pHOST_RX_RAM_Addr;
extern PUINT8  pHOST_TX_RAM_Addr;

extern UINT8  Com_Buffer[];

 
extern const UINT8  SetupGetDevDescr[];    
extern const UINT8  SetupGetCfgDescr[];    
extern const UINT8  SetupSetUsbAddr[];     
extern const UINT8  SetupSetUsbConfig[];   
extern const UINT8  SetupSetUsbInterface[];
extern const UINT8  SetupClrEndpStall[];   


void  DisableRootHubPort(void)  ;                   
UINT8   AnalyzeRootHub( void ) ;         

void    SetHostUsbAddr( UINT8 addr );                 
void    SetUsbSpeed( UINT8 FullSpeed );               
void    ResetRootHubPort(void);                          
UINT8   EnableRootHubPort(void);                          
void    SelectHubPort( UINT8 HubPortIndex );
UINT8   WaitUSB_Interrupt( void );                    

UINT8   USBHostTransact( UINT8 endp_pid, UINT8 tog, UINT32 timeout );  
UINT8   HostCtrlTransfer( PUINT8 DataBuf, PUINT8 RetLen );  



void CopySetupReqPkg( PCCHAR pReqPkt );            
UINT8 CtrlGetDeviceDescr( void );                    
UINT8 CtrlGetConfigDescr( void );                    
UINT8 CtrlSetUsbAddress( UINT8 addr );                         
UINT8 CtrlSetUsbConfig( UINT8 cfg );                           
UINT8 CtrlClearEndpStall( UINT8 endp ) ;                       
UINT8 CtrlSetUsbIntercace( UINT8 cfg );					       


void    USB_HostInit( void );                                  



 


UINT8 InitRootDevice( void ); 

UINT8   CtrlGetHIDDeviceReport( UINT8 infc );          
UINT8   CtrlGetHubDescr( void );                       
UINT8   HubGetPortStatus( UINT8 HubPortIndex );        
UINT8   HubSetPortFeature( UINT8 HubPortIndex, UINT8 FeatureSelt );  
UINT8   HubClearPortFeature( UINT8 HubPortIndex, UINT8 FeatureSelt );  
	 	 
	 
	 






#line 57 "..\\SRC\\StdPeriphDriver\\inc\\CH57x_common.h"




  










#line 12 "..\\SRC\\StdPeriphDriver\\CH57x_flash.c"

 



 
unsigned char codeflash_access_flag1 = 0x0;
unsigned char codeflash_access_flag2 = 0x0;






 
void GetUniqueID(PUINT8 buf)
{
    PUINT8  pID;
    UINT8   i;
    
    pID = (PUINT8)0x40608;
    for(i=0; i<8; i++) *buf++ = *pID++;
}






 
void GetMACAddress(PUINT8 buf)
{
    PUINT8  pMAC;
    UINT8   i;
    
    pMAC = (PUINT8)0x40608;
    for(i=0; i<6; i++) *buf++ = *pMAC++;
}








 
UINT8 FlashBlockErase(UINT32 addr)
{
    UINT8  status = 0;
	volatile UINT8  op_step;
	
    if( addr & (0x200-1) )          return 1;  
	
	op_step = 0x11;
	codeflash_access_flag1 = 0;
	codeflash_access_flag2 = 0;
	(*((PUINT8V)0x40001809)) = 0x80;
	
	
	op_step += 0x11;	
	if(((*((PUINT8V)0x40001024)) & 0x0F) != 0x0D)		PowerMonitor( (!0) );
	
	op_step += 0x11;
	if(((*((PUINT8V)0x40001026)) & 0x03) != 0x00) 		return 2;  
		
	op_step += 0x11;
	if((((*((PUINT8V)0x40001026)) & 0x03) == 0x00)
		&&(op_step == 0x44))
	{
		codeflash_access_flag1 = 0x57;
	}
	
	op_step += 0x11;
	if((((*((PUINT8V)0x40001026)) & 0x03) == 0x00)
		&&(op_step == 0x55)
	    &&(codeflash_access_flag1 == 0x57))
	{
		codeflash_access_flag2 = 0xA8;
	}	
	
	op_step += 0x11;
	if((codeflash_access_flag1 == 0x57)
	 &&(codeflash_access_flag2 == 0xA8)
	 &&(op_step == 0x66))
	{
		(*((PUINT32V)0x40001804)) = addr;
        if( addr < 0x3E800  )    (*((PUINT8V)0x40001809)) = 0x80|0x08;	
        else       (*((PUINT8V)0x40001809)) = 0x80|0x04;         
	}
	
	op_step += 0x11;
	 
	if((codeflash_access_flag1 == 0x57)
	 &&(codeflash_access_flag2 == 0xA8)
	 &&(op_step == 0x77))
	{
		(*((PUINT8V)0x40001808)) = 0xA6;
		status = (unsigned char)((*((PUINT16V)0x4000180A)) & 0xff);
	}
	
	op_step = 0x00;
	codeflash_access_flag1 = 0x00;
	codeflash_access_flag2 = 0x00;
	(*((PUINT8V)0x40001809)) = 0x80;		
	
	if( status != 0x40 )  return 3;   
	return 0;
}










 
UINT8 FlashWriteDW(UINT32 addr, UINT32 dat)
{
    UINT32  add = addr;
    UINT32  val = dat;
    UINT8  status = 0;	
	volatile UINT8  op_step;

    if( addr & (4-1) )              return 1; 
	
	op_step = 0x11;
	codeflash_access_flag1 = 0;
	codeflash_access_flag2 = 0;
	(*((PUINT8V)0x40001809)) = 0x80;
	
	
	op_step += 0x11;	
	if(((*((PUINT8V)0x40001024)) & 0x0F) != 0x0D)		PowerMonitor( (!0) );

	op_step += 0x11;
	if(((*((PUINT8V)0x40001026)) & 0x03) != 0x00) 		return 2;  

	op_step += 0x11;
	if((((*((PUINT8V)0x40001026)) & 0x01) == 0x00)
		&&(op_step == 0x44))
	{
		codeflash_access_flag1 = 0x57;
	}
	
	op_step += 0x11;
	if((((*((PUINT8V)0x40001026)) & 0x01) == 0x00)
		&&(op_step == 0x55)
		&&(codeflash_access_flag1 == 0x57))
	{
		codeflash_access_flag2 = 0xA8;
	}

	op_step += 0x11;
	if((codeflash_access_flag1 == 0x57)
	 &&(codeflash_access_flag2 == 0xA8)
	 &&(op_step == 0x66))
	{
		if( addr < 0x3E800  )    (*((PUINT8V)0x40001809)) = 0x80|0x08;	
        else       (*((PUINT8V)0x40001809)) = 0x80|0x04;         
	}
	
    op_step += 0x11;
	 
	if((codeflash_access_flag1==0x57)
	 &&(codeflash_access_flag2==0xA8)
	 &&(op_step == 0x77))
	{
		(*((PUINT32V)0x40001804)) = add;
		(*((PUINT32V)0x40001800)) = val;		
		(*((PUINT8V)0x40001808)) = 0x9A;
		status = (unsigned char)((*((PUINT16V)0x4000180A)) & 0xff);
	}
	
	op_step = 0x00;
	codeflash_access_flag1 = 0x00;
	codeflash_access_flag2 = 0x00;
	(*((PUINT8V)0x40001809)) = 0x80;
	if( status != 0x40 )  return 3;  
	
	return 0;	
	
}










 
UINT8 FlashWriteBuf(UINT32 addr, PUINT32 pdat, UINT16 len)
{
    UINT32  add = addr;
    PUINT32 p32 = pdat;
    UINT8  status = 0;	
	UINT16  i;
	volatile UINT8  op_step;

    if( addr & (4-1) )              return 1; 
	
	op_step = 0x11;
	codeflash_access_flag1 = 0;
	codeflash_access_flag2 = 0;
	(*((PUINT8V)0x40001809)) = 0x80;
	
	
	op_step += 0x11;	
	if(((*((PUINT8V)0x40001024)) & 0x0F) != 0x0D)		PowerMonitor( (!0) );

	op_step += 0x11;
	if(((*((PUINT8V)0x40001026)) & 0x03) != 0x00) 		return 2;  

	op_step += 0x11;
	if((((*((PUINT8V)0x40001026)) & 0x01) == 0x00)
		&&(op_step == 0x44))
	{
		codeflash_access_flag1 = 0x57;
	}
	
	op_step += 0x11;
	if((((*((PUINT8V)0x40001026)) & 0x01) == 0x00)
		&&(op_step == 0x55)
		&&(codeflash_access_flag1 == 0x57))
	{
		codeflash_access_flag2 = 0xA8;
	}

	op_step += 0x11;
	if((codeflash_access_flag1 == 0x57)
	 &&(codeflash_access_flag2 == 0xA8)
	 &&(op_step == 0x66))
	{
		if( addr < 0x3E800  )    (*((PUINT8V)0x40001809)) = 0x80|0x08;	
        else       (*((PUINT8V)0x40001809)) = 0x80|0x04;         
	}
	
    op_step += 0x11;
	 
	if((codeflash_access_flag1==0x57)
	 &&(codeflash_access_flag2==0xA8)
	 &&(op_step == 0x77))
	{
		for(i=0; i<len; i+=4)
		{
			(*((PUINT32V)0x40001804)) = add;
			(*((PUINT32V)0x40001800)) = *p32++;		
			(*((PUINT8V)0x40001808)) = 0x9A;		
			add += 4;
			
			status = (unsigned char)((*((PUINT16V)0x4000180A)) & 0xff);
			if( status != 0x40 )  break;
		}
	}
	
	op_step = 0x00;
	codeflash_access_flag1 = 0x00;
	codeflash_access_flag2 = 0x00;
	(*((PUINT8V)0x40001809)) = 0x80;
	if( status != 0x40 )  return 3;  
	
	return 0;
}



